#ifndef _IUINTERFACE_HPP_
#define _IUINTERFACE_HPP_

#ifdef _SOLARIS_
#include <inttypes.h>
#else
#include <stdint.h>
#endif
#include <pthread.h>
#include "iuMacAddress.hpp"
#include "iuIPAddress.hpp"

class iuPacket;

/**
 * @brief Classe abstraite servant de base aux differents types d'interfaces reseau (socket, FIFO)
 */
class iuInterface
{
public:
   iuInterface();
   virtual ~iuInterface() {}

   bool         isOpen();
   virtual bool open(uint16_t port) = 0;
   virtual void close() = 0;
   virtual int  getReceiveFD() = 0;

   virtual uint16_t receive(char **buffer) = 0;
   virtual uint16_t send(char *buffer, uint16_t len) = 0;
   iuPacket        *receivePacket(uint16_t *protocol);
   bool             sendPacket(iuPacket &packet, const iuMacAddress &dest, uint16_t protocol);

   bool                isActive();
   void                setActive(bool active);

   void                configure(const iuIPAddress &ip, const iuIPAddress &netmask, const iuIPAddress &broadcast, uint16_t mtu);
   unsigned char       getNumber();
   uint16_t            getPort();
   const iuMacAddress &getMAC();
   const iuIPAddress  &getIP();
   const iuIPAddress  &getNetmask();
   const iuIPAddress  &getBroadcast();
   uint16_t            getMTU();

   iuInterface *next;

protected:
   static unsigned char m_nextNumber;
   static pthread_mutex_t m_mutex;

   bool m_isOpen;
   bool m_isActive;
   unsigned char m_number;
   uint16_t m_port;

   iuMacAddress m_macAddress;
   iuIPAddress m_ip;
   iuIPAddress m_netmask;
   iuIPAddress m_broadcast;
   uint16_t m_mtu;
};

#endif
